/*
 * CharacterDataImp.cpp
 *
 *  Created on: Apr 27, 2009
 *      Author: wrice
 */
//#include ".h"
#include "DOMCoreImp.h"
namespace DOMCoreImp {

CharacterDataImp::CharacterDataImp(DOMString nodeName, DOMString data, DocumentImp * ownerDocument)
: NodeImp(nodeName, ownerDocument)
{
	setNodeValue( data );
}

DOMString CharacterDataImp::getData() throw(DOMExceptionPtr) {
	return getNodeValue();
}

void CharacterDataImp::setData(DOMString data) throw(DOMExceptionPtr) {
	setNodeValue( data );
}

unsigned long CharacterDataImp::getLength() {
	return getNodeValue().length();
}

DOMString CharacterDataImp::substringData(unsigned long offset, unsigned long count) throw(DOMExceptionPtr) {
	if( offset + count > getLength() )
		throw DOMExceptionPtr(new DOMExceptionImp(DOMException::INDEX_SIZE_ERR));
	return getNodeValue().substr( offset, count );
}

void CharacterDataImp::appendData(DOMString arg) throw(DOMExceptionPtr) {
	setNodeValue( getNodeValue() + arg );
}

void CharacterDataImp::insertData(unsigned long offset, DOMString arg) throw(DOMExceptionPtr) {
	if( offset > getLength() )
		throw DOMExceptionPtr(new DOMExceptionImp(DOMException::INDEX_SIZE_ERR));
	setNodeValue( getNodeValue().insert( offset, arg ) );
}

void CharacterDataImp::deleteData(unsigned long offset, unsigned long count) throw(DOMExceptionPtr) {
	if( offset + count > getLength() )
		throw DOMExceptionPtr(new DOMExceptionImp(DOMException::INDEX_SIZE_ERR));
	setNodeValue( getNodeValue().erase( offset, count ) );
}

void CharacterDataImp::replaceData(unsigned long offset, unsigned long count, DOMString arg) throw(DOMExceptionPtr) {
	if( offset + count > getLength() )
		throw DOMExceptionPtr(new DOMExceptionImp(DOMException::INDEX_SIZE_ERR));
	setNodeValue( getNodeValue().replace( offset, count, arg ) );
}


}

